/*
 * @Author: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @Date: 2025-07-01 14:13:54
 * @LastEditors: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @LastEditTime: 2025-09-03 02:48:47
 * @FilePath: \keep_motion_api\models\data\ranking.model.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

// 排名模型
const rankingSchema = new Schema({
  type: {
    type: String,
    enum: ["daily", "weekly", "monthly", "all_time"],
    required: true
  },
  category: {
    type: String,
    enum: ["steps", "calories", "duration", "distance", "course_completion"],
    required: true
  },
  rankings: [{
    user_id: { 
      type: Schema.Types.ObjectId, 
      ref: 'User',
      required: true 
    },
    value: Number,
    rank: Number
  }],
  update_time: { type: Date, default: Date.now },
  reward_distributed: {
    type: Boolean,
    default: false
  },
  reward_details: Object
});
rankingSchema.statics.getRankings = async function (type, category) {
  return await this.find({ type, category });
}
rankingSchema.statics.generateRankings = async function (type, category) {
  return await this.find({ type, category });
}
rankingSchema.statics.distributeRewards = async function (type, category) {
  return await this.find({ type, category });
}
rankingSchema.statics.getHistory = async function (type, category) {
  return await this.find({ type, category });
}
module.exports = mongoose.model('Ranking', rankingSchema);
